Skip to content

Optimize Docker build with dependency layer caching#36864

Merged
silverwind merged 3 commits intogo-gitea:mainfrom
silverwind:dockercache
Mar 8, 2026
Merged

Optimize Docker build with dependency layer caching#36864
silverwind merged 3 commits intogo-gitea:mainfrom
silverwind:dockercache

Conversation

@silverwind
Copy link
Copy Markdown
Member

@silverwind silverwind commented Mar 8, 2026

  1. Copy dependency manifests before the full source copy so that dependency installation gets its own cached layer. When only source code changes, the dependency layers are reused.
  2. Remove the GOPROXY=direct override which was bypassing the Go module proxy, causing build failures when git servers are unreachable. The Go default (https://proxy.golang.org,direct) is now used instead.

Copy dependency manifests (package.json, pnpm-lock.yaml, .npmrc for
npm; go.mod, go.sum for Go) before the full source copy so that
dependency installation gets its own cached layer. When only source
code changes, the dependency layers are reused.

Also remove the GOPROXY=direct override which was bypassing the Go
module proxy, causing build failures when gitea.com was unreachable.
The Go default (https://proxy.golang.org,direct) is now used instead.

Co-Authored-By: Claude (Opus 4.6) <noreply@anthropic.com>
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 8, 2026
The node_modules directory created by pnpm install always has a newer
mtime than the pnpm-lock.yaml copied from the build context, so make
already sees node_modules as up-to-date.

Co-Authored-By: Claude (Opus 4.6) <noreply@anthropic.com>
@silverwind silverwind added the topic/build PR changes how Gitea is built, i.e. regarding Docker or the Makefile label Mar 8, 2026
@silverwind silverwind requested a review from Copilot March 8, 2026 11:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the project Docker build to improve build caching and reliability by separating dependency installation into its own cached layers and by reverting Go module fetching to the default proxy behavior.

Changes:

  • Frontend: copy package.json/pnpm-lock.yaml/.npmrc first and run pnpm install before copying the rest of the source.
  • Backend: copy go.mod/go.sum first and run go mod download before copying the full source tree.
  • Remove the GOPROXY=direct build-arg override so Go uses its default proxy configuration.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
Dockerfile Adds separate cached layers for pnpm/go module dependencies; removes GOPROXY=direct.
Dockerfile.rootless Mirrors the same dependency-layer caching and GOPROXY change for the rootless image.
Comments suppressed due to low confidence (2)

Dockerfile:18

  • ARG GITEA_VERSION/TAGS/CGO_EXTRA_CFLAGS are declared before the COPY go.mod go.sum + go mod download dependency layer. With BuildKit, changing any of these build-args can invalidate the cache for subsequent RUN steps, defeating the intended module-download caching when only the version/tags change. Consider moving these ARG/ENV declarations to just before make backend so the go mod download layer only depends on go.mod/go.sum (and base image/apk deps).
ARG GITEA_VERSION
ARG TAGS="sqlite sqlite_unlock_notify"
ENV TAGS="bindata timetzdata $TAGS"
ARG CGO_EXTRA_CFLAGS

Dockerfile.rootless:18

  • Same caching concern here: build args (GITEA_VERSION/TAGS/CGO_EXTRA_CFLAGS) are declared before the go mod download layer, so varying them can invalidate the module download cache even when go.mod/go.sum are unchanged. Moving the ARG/ENV declarations to just before make backend would keep the dependency layer reusable across version/tag-only rebuilds.
ARG GITEA_VERSION
ARG TAGS="sqlite sqlite_unlock_notify"
ENV TAGS="bindata timetzdata $TAGS"
ARG CGO_EXTRA_CFLAGS


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Mar 8, 2026
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Mar 8, 2026
@silverwind silverwind added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 8, 2026
@silverwind silverwind enabled auto-merge (squash) March 8, 2026 15:58
@silverwind silverwind merged commit 23a5bc5 into go-gitea:main Mar 8, 2026
25 checks passed
@silverwind silverwind deleted the dockercache branch March 8, 2026 15:58
@GiteaBot GiteaBot added this to the 1.26.0 milestone Mar 8, 2026
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 8, 2026
silverwind added a commit to silverwind/gitea that referenced this pull request Mar 8, 2026
* origin/main:
  Optimize Docker build with dependency layer caching (go-gitea#36864)
  Fix URLJoin, markup render link reoslving, sign-in/up/linkaccount page common data (go-gitea#36861)
  Fix CodeQL code scanning alerts (go-gitea#36858)
  Refactor auth middleware (go-gitea#36848)
  Update Nix flake (go-gitea#36857)
  Update JS deps (go-gitea#36850)
  Load `mentionValues` asynchronously (go-gitea#36739)
  [skip ci] Updated translations via Crowdin
silverwind added a commit to silverwind/gitea that referenced this pull request Mar 8, 2026
* main: (26 commits)
  Clean up `refreshViewedFilesSummary` (go-gitea#36868)
  Remove `util.URLJoin` and replace all callers with direct path concatenation (go-gitea#36867)
  Optimize Docker build with dependency layer caching (go-gitea#36864)
  Fix URLJoin, markup render link reoslving, sign-in/up/linkaccount page common data (go-gitea#36861)
  Fix CodeQL code scanning alerts (go-gitea#36858)
  Refactor auth middleware (go-gitea#36848)
  Update Nix flake (go-gitea#36857)
  Update JS deps (go-gitea#36850)
  Load `mentionValues` asynchronously (go-gitea#36739)
  [skip ci] Updated translations via Crowdin
  Fix dbfs error handling (go-gitea#36844)
  Fix OAuth2 authorization code expiry and reuse handling (go-gitea#36797)
  Fix org permission API visibility checks for hidden members and private orgs (go-gitea#36798)
  Fix non-admins unable to automerge PRs from forks (go-gitea#36833)
  upgrade to github.com/cloudflare/circl 1.6.3, svgo 4.0.1, markdownlint-cli 0.48.0 (go-gitea#36837)
  Fix dump release asset bug (go-gitea#36799)
  build(deps): update material-icon-theme v5.32.0 (go-gitea#36832)
  Fix bug to check whether user can update pull request branch or rebase branch (go-gitea#36465)
  Fix forwarded proto handling for public URL detection (go-gitea#36810)
  Fix artifacts v4 backend upload problems (go-gitea#36805)
  ...

# Conflicts:
#	pnpm-lock.yaml
zjjhot added a commit to zjjhot/gitea that referenced this pull request Mar 10, 2026
* giteaofficial/main:
  Update minimum go version to 1.26.1, golangci-lint to 2.11.2, fix test style (go-gitea#36876)
  Add render cache for SVG icons (go-gitea#36863)
  Fix incorrect viewed files counter if reverted change was viewed (go-gitea#36819)
  [skip ci] Updated translations via Crowdin
  Clean up `refreshViewedFilesSummary` (go-gitea#36868)
  Remove `util.URLJoin` and replace all callers with direct path concatenation (go-gitea#36867)
  Optimize Docker build with dependency layer caching (go-gitea#36864)
  Fix URLJoin, markup render link reoslving, sign-in/up/linkaccount page common data (go-gitea#36861)
  Fix CodeQL code scanning alerts (go-gitea#36858)
  Refactor auth middleware (go-gitea#36848)
  Update Nix flake (go-gitea#36857)
  Update JS deps (go-gitea#36850)
  Load `mentionValues` asynchronously (go-gitea#36739)
  [skip ci] Updated translations via Crowdin
  Fix dbfs error handling (go-gitea#36844)
  Fix OAuth2 authorization code expiry and reuse handling (go-gitea#36797)
  Fix org permission API visibility checks for hidden members and private orgs (go-gitea#36798)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/internal topic/build PR changes how Gitea is built, i.e. regarding Docker or the Makefile

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants